
import java.io.FileDescriptor;

/**
 * ClassName: DefaultSecurityManager
 * Package: com.fa.ojcodesandbox.security
 * Description: 默认安全管理器
 *
 * @Author:
 * @Create: 2024/4/27 - 22:12
 * @Version: v1.0
 */
public class MySecurityManager extends SecurityManager{


    /**
     * 检查程序是否可执行文件
     * @param cmd   the specified system command.
     */
    @Override
    public void checkExec(String cmd) {
        if ("java".equals(cmd)) {
            return;
        }
        throw new SecurityException("checkExec 权限异常：" + cmd);
    }

    /**
     * 检查程序是否可读取文件
     * @param fd   the system-dependent file descriptor.
     */
    @Override
    public void checkRead(FileDescriptor fd) {

        throw new SecurityException("checkRead 权限异常：" + fd);
    }

    /**
     * 检查程序是否可以写文件
     * @param file   the system-dependent filename.
     */
    @Override
    public void checkWrite(String file) {
        throw new SecurityException("checkWrite 权限异常：" + file);
    }

    /**
     * 检查程序是否可以删除文件
     * @param file   the system-dependent filename.
     */
    @Override
    public void checkDelete(String file) {
        throw new SecurityException("checkDelete 权限异常：" + file);
    }

    /**
     * 检查程序是否可以进行网络连接
     * @param host   the host name port to connect to.
     * @param port   the protocol port to connect to.
     */
    @Override
    public void checkConnect(String host, int port) {
        throw new SecurityException("checkConnect 权限异常：" + host + ":" + port);
    }
}
